// 销售数据看板类型定义

// ============ 枚举类型 ============

export enum ErrorType {
  NETWORK_ERROR = 'NETWORK_ERROR',
  API_ERROR = 'API_ERROR',
  DATA_PARSE_ERROR = 'DATA_PARSE_ERROR',
  RENDER_ERROR = 'RENDER_ERROR',
  CONFIG_ERROR = 'CONFIG_ERROR',
  PERMISSION_ERROR = 'PERMISSION_ERROR'
}

export enum ProjectStatus {
  PLANNING = 'planning',
  IN_PROGRESS = 'in-progress',
  DELAYED = 'delayed',
  COMPLETED = 'completed'
}

export enum ContractStatus {
  PENDING = 'pending',
  ACTIVE = 'active',
  COMPLETED = 'completed',
  CANCELLED = 'cancelled'
}

export enum RiskLevel {
  LOW = 'low',
  MEDIUM = 'medium',
  HIGH = 'high'
}

// ============ 基础数据模型 ============

export interface SalesOverview {
  totalRevenue: number
  totalContracts: number
  activeProjects: number
  completionRate: number
  monthlyTrend: MonthlyData[]
  topPerformers: Performer[]
}

export interface MonthlyData {
  month: string
  revenue: number
  contracts: number
  growth: number
}

export interface Performer {
  id: string
  name: string
  revenue: number
  contracts: number
  avatar?: string
}

export interface Contract {
  id: string
  name: string
  client: string
  amount: number
  status: ContractStatus
  signDate: Date
  expiryDate: Date
  progress: number
  description?: string
}

export interface Project {
  id: string
  name: string
  contractId: string
  status: ProjectStatus
  progress: number
  startDate: Date
  deadline: Date
  team: TeamMember[]
  milestones: Milestone[]
  riskLevel: RiskLevel
  description?: string
}

export interface TeamMember {
  id: string
  name: string
  role: string
  avatar?: string
}

export interface Milestone {
  id: string
  name: string
  deadline: Date
  completed: boolean
  description?: string
}

export interface TimeSeriesData {
  timestamp: Date
  value: number
  metric: string
  metadata?: Record<string, any>
}

// ============ 配置相关 ============

export interface UserConfig {
  layout: LayoutConfig
  visibleMetrics: string[]
  refreshInterval: number
  theme: ThemeConfig
  chartPreferences: ChartPreferences
}

export interface LayoutConfig {
  type: 'grid' | 'flex' | 'masonry'
  columns?: number
  gap?: number
  moduleOrder?: string[]
}

export interface ThemeConfig {
  name: 'tech-dark' | 'tech-blue' | 'tech-purple'
  customColors?: {
    primary?: string
    secondary?: string
    accent?: string
  }
}

export interface ChartPreferences {
  showGrid?: boolean
  showLegend?: boolean
  showTooltip?: boolean
  animationDuration?: number
  smoothCurves?: boolean
}

// ============ 图表相关 ============

export interface ChartData {
  labels: string[]
  datasets: Dataset[]
  title?: string
  subtitle?: string
}

export interface Dataset {
  label: string
  data: number[]
  color?: string
  type?: 'line' | 'bar' | 'pie' | 'scatter' | 'gauge'
}

export interface ChartOptions {
  responsive?: boolean
  maintainAspectRatio?: boolean
  animation?: boolean
  legend?: {
    display?: boolean
    position?: 'top' | 'bottom' | 'left' | 'right'
  }
  tooltip?: {
    enabled?: boolean
    mode?: 'point' | 'index' | 'dataset'
  }
}

// ============ API 相关 ============

export interface ContractQueryParams {
  status?: ContractStatus
  startDate?: Date
  endDate?: Date
  client?: string
  limit?: number
  offset?: number
}

export interface ProjectQueryParams {
  status?: ProjectStatus
  riskLevel?: RiskLevel
  startDate?: Date
  endDate?: Date
  limit?: number
  offset?: number
}

export interface TimeRange {
  start: Date
  end: Date
}

export interface ApiResponse<T> {
  data: T
  success: boolean
  message?: string
  timestamp: Date
}

export interface PaginatedResponse<T> {
  data: T[]
  total: number
  page: number
  pageSize: number
  hasMore: boolean
}

// ============ 错误处理 ============

export interface AppError {
  type: ErrorType
  message: string
  code?: string
  details?: any
  timestamp: Date
  recoverable: boolean
}

// ============ 组件 Props ============

export interface DashboardLayoutProps {
  layout: 'grid' | 'flex' | 'masonry'
  columns?: number
  gap?: number
}

export interface DataCardProps {
  title: string
  icon?: string
  loading?: boolean
  glowEffect?: boolean
  animationDelay?: number
}

export interface ChartWrapperProps {
  chartType: 'line' | 'bar' | 'pie' | 'scatter' | 'gauge'
  data: ChartData
  options?: ChartOptions
  theme?: 'tech-dark' | 'tech-blue' | 'tech-purple'
  autoResize?: boolean
}

export interface TrendChartProps {
  data: TimeSeriesData[]
  timeRange: [Date, Date]
  metrics: string[]
  showGradient?: boolean
  showGlow?: boolean
  interactive?: boolean
}

export interface ContractOverviewProps {
  contracts: Contract[]
  displayMode: 'summary' | 'detailed'
  refreshInterval?: number
}

export interface ProjectTrackerProps {
  projects: Project[]
  highlightRisks?: boolean
  sortBy?: 'status' | 'deadline' | 'priority'
}

export interface AnimatedNumberProps {
  value: number
  duration?: number
  format?: (value: number) => string
  prefix?: string
  suffix?: string
}

// ============ 工具类型 ============

export type Nullable<T> = T | null
export type Optional<T> = T | undefined
export type AsyncData<T> = {
  data: Nullable<T>
  loading: boolean
  error: Nullable<AppError>
}

// ============ 常量 ============

export const DEFAULT_REFRESH_INTERVAL = 30000 // 30 seconds
export const DEFAULT_PAGE_SIZE = 20
export const MAX_RETRY_ATTEMPTS = 3
export const CHART_ANIMATION_DURATION = 750
export const DATA_CACHE_TTL = 60000 // 1 minute
